package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.WorkshopWarehouseKindPresenter
import com.weetop.cfw.base.presenter.WorkshopWarehouseKindView
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import com.weetop.cfw.base.ui.fragment.CommonBaseFragment
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.bean.LeaseSaleBrowsingRecordBean
import com.weetop.cfw.bean.WorkshopWarehouseListBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.home_page.fragment.WorkshopWarehouseKindFragment
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class WorkshopWarehouseKindPresenterImp(var workshopWarehouseKindView: WorkshopWarehouseKindView? = null): WorkshopWarehouseKindPresenter {
    /**
     * 获取厂房分类列表数据
     */
    override fun getWorkshopWarehouseListData(baseFragment:CommonBaseFragment, queryMap: Map<String, String>) {
        //baseFragment.showLoadingDialog(baseFragment.activity as CommonBaseActivity,"正在获取厂房列表数据...")
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getWorkshopWarehouseList(queryMap = queryMap),baseFragment,object:RxJavaCallBack<WorkshopWarehouseListBean>(){
            override fun onSuccess(t: WorkshopWarehouseListBean?) {
                baseFragment.dismissLoadingDialog()
                workshopWarehouseKindView?.workshopWarehouseListDataGetSuccess(t)
            }

            override fun onRequestError(t: WorkshopWarehouseListBean?) {
                super.onRequestError(t)
                baseFragment.dismissLoadingDialog()
                workshopWarehouseKindView?.workshopWarehouseListDataGetFailed()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                baseFragment.dismissLoadingDialog()
                workshopWarehouseKindView?.workshopWarehouseListDataGetFailed()
            }
        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        workshopWarehouseKindView = baseView as? WorkshopWarehouseKindView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        workshopWarehouseKindView = null
    }
}